<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>leenty blog</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="leenty 不会捣(xia)鼓(gao)的前端不是好全栈">
<meta name="keywords" content="前端,vuejs,vue-router,vuex,vue-cli,javascript,js,mvvm,css3,html5,git,github">
<meta property="og:type" content="website">
<meta property="og:title" content="leenty blog">
<meta property="og:url" content="http://baidu.com/page/2/index.html">
<meta property="og:site_name" content="leenty blog">
<meta property="og:description" content="leenty 不会捣(xia)鼓(gao)的前端不是好全栈">
<meta property="og:locale" content="zh-CN">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="leenty blog">
<meta name="twitter:description" content="leenty 不会捣(xia)鼓(gao)的前端不是好全栈">
  
    <link rel="alternative" href="/atom.xml" title="leenty blog" type="application/atom+xml">
  
  
    <link rel="icon" href="//favicon.png">
  
  <script src="/style.js"></script>
  

  
<!-- baidu_tongji -->
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?5bae4c35e53fde3bf2526312c3edaf1d";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>
<!-- End baidu_tongji -->


</head>
</html>
<body>
  <div id="container">
    <div class="left-col">
      <div class="overlay"></div>
<div class="intrude-less">
	<header id="header" class="inner">
		<a href="/" class="profilepic">
			
			<img src="/img/default_avatar.png" class="js-avatar">
			
		</a>

		<hgroup>
		  <h1 class="header-author"><a href="/">leenty</a></h1>
		</hgroup>

		

		<nav class="header-menu">
			<ul>
			
				<li><a href="/">主页</a></li>
	        
				<li><a href="/archives">所有文章</a></li>
	        
			</ul>
		</nav>
		<nav class="header-smart-menu">
	        
    		
    			
    			<a class="js-smart-menu" data-idx="0" href="javascript:void(0)">所有文章</a>
    			
    			
            
    			
    			<a class="js-smart-menu" data-idx="1" href="javascript:void(0)">标签</a>
    			
    			
            
    			
    			<a class="js-smart-menu" data-idx="2" href="javascript:void(0)">友链</a>
    			
    			
            
    			
    			<a class="js-smart-menu" data-idx="3" href="javascript:void(0)">关于我</a>
    			
    			
            
		</nav>
		<nav class="header-nav">
			<div class="social">
				
					<a class="github" target="_blank" href="https://github.com/leenty" title="github">github</a>
		        
			</div>
		</nav>
	</header>		
</div>

    </div>
    <div class="mid-col">
      <nav id="mobile-nav">
  	<div class="overlay">
  		<div class="slider-trigger"><i class="icon-list"></i></div>
  		<h1 class="header-author js-mobile-header hide">leenty</h1>
  	</div>
	<div class="intrude-less">
		<header id="header" class="inner">
			<div class="profilepic">
				
					<img src="/img/default_avatar.png" class="js-avatar">
				
			</div>
			<hgroup>
			  <h1 class="header-author">leenty</h1>
			</hgroup>
			
			<nav class="header-menu">
				<ul>
				
					<li><a href="/">主页</a></li>
		        
					<li><a href="/archives">所有文章</a></li>
		        
				</ul>
			</nav>
			<nav class="header-nav">
				<div class="social">
					
						<a class="github" target="_blank" href="https://github.com/leenty" title="github">github</a>
			        
				</div>
			</nav>
		</header>				
	</div>
</nav>

      <div class="body-wrap">
        
  
    <article id="post-interesting_button_by_css" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-inner">
    
      <input type="hidden" class="isFancy" />
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2016/11/16/interesting_button_by_css/">使用纯css制作有炫酷交互的按钮</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="前端入门简单，真正精通却不那么容易"><a href="#前端入门简单，真正精通却不那么容易" class="headerlink" title="前端入门简单，真正精通却不那么容易"></a>前端入门简单，真正精通却不那么容易</h3><p>就css来说，会使用css做页面布局也只是第一步，css远比想象中的要强大。</p>
<p>js很多效果都可以利用css各种属性和伪元素，制作出来，而且比起js还要方便快速</p>
<p>这是一个菜单按钮的效果，成为焦点后会变成一把叉，在焦点移除后会还原会菜单形状<br>这时就可以配合js做状态管理写出一个完整的下拉菜单或者侧拉菜单了<br>之后也会使用在我的vue2.0项目中，如果爷您有兴趣可以<a href="http://vue2.leenty.com" target="_blank" rel="noopener">移步到项目地址处视察视察</a>，如果爷开心了就加个星</p>
<p>具体的效果是这样的<br><img src="http://upload-images.jianshu.io/upload_images/2005796-564670324f24a925.gif?imageMogr2/auto-orient/strip" alt="rotate menu button by css"></p>
<iframe height="265" scrolling="no" title="rotate menu button by css" src="//codepen.io/leenty/embed/PbGpEg/?height=265&theme-id=0&default-tab=css,result&embed-version=2" frameborder="no" allowtransparency="true" allowfullscreen="true" style="width: 100%;">See the Pen <a href="http://codepen.io/leenty/pen/PbGpEg/" target="_blank" rel="noopener">rotate menu button by css</a> by leenty (<a href="http://codepen.io/leenty" target="_blank" rel="noopener">@leenty</a>) on <a href="http://codepen.io" target="_blank" rel="noopener">CodePen</a>.<br></iframe><br><a href="http://codepen.io/leenty/pen/PbGpEg" target="_blank" rel="noopener">这里是menu按钮的演示地址</a><br><br>写代码要信奉“能偷懒就偷懒”原则，在保证实现效果的基础上，绝不多写一个标签，多写一段代码<br>所以上面的效果咋一看需要至少4个标签才能写完，其实只用了一个标签<br>用button标签做父元素，用两个伪元素做两个横杆<br>问：“那还有一个横杆呢？”<br>是这样，通过观察效果图，发现其实由菜单图标变换到X图标只需要其中的两个横杆。<br>所以第三个横杆我使用了box-shadow属性来模拟，说到底，其实第三个横杆只是第二个横杆的投影而已<br><br>核心使用<br><em> 属性：<code>transform-origin</code>, <code>transform</code>, <code>box-shadow</code>, <code>transition</code>
</em> 伪元素：<code>:before</code>, <code>:after</code><br><br>代码标签是用pug语法写的，css是stylus语法写的，这两种语法都比较简单，如果会使用css选择器就可以看懂<br>下面也会简单的说明下<br><br>话不多说，上代码<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">button#btn.b-menu</span><br><span class="line"><span class="comment">// pug语法里的'#'和'.'同css里一样'#'为id，'.'为class</span></span><br><span class="line">label(<span class="keyword">for</span>=<span class="string">"btn"</span>) click</span><br><span class="line"><span class="comment">// 除了id与class以外的属性要如上面的形式写在括号里</span></span><br><span class="line">    </span><br><span class="line"><span class="comment">// 这里扩展出来就是</span></span><br><span class="line"><span class="comment">// &lt;button id="btn" class="b-menu"&gt;&lt;/button&gt;</span></span><br><span class="line"><span class="comment">// &lt;label for="btn"&gt;click&lt;/label&gt;</span></span><br></pre></td></tr></table></figure><br><br><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line">// stylus是css的预编译器的一种，简化了css的写法，结构更加清晰</span><br><span class="line">// 这里就不过多的陈述了，有疑问可以下方留言询问</span><br><span class="line"> </span><br><span class="line">// 先去除button的默认样式</span><br><span class="line"><span class="selector-tag">button</span></span><br><span class="line">  <span class="selector-tag">border</span> <span class="selector-tag">none</span></span><br><span class="line">  <span class="selector-tag">outline</span> <span class="selector-tag">none</span></span><br><span class="line">  <span class="selector-tag">box-shadow</span> <span class="selector-tag">none</span></span><br><span class="line">  <span class="selector-tag">background</span> <span class="selector-tag">none</span></span><br><span class="line">  <span class="selector-tag">color</span> <span class="selector-tag">currentColor</span></span><br><span class="line">  <span class="selector-tag">padding</span> 0</span><br><span class="line">  <span class="selector-tag">cursor</span> <span class="selector-tag">pointer</span></span><br><span class="line"> </span><br><span class="line">// 关键的部分开始了</span><br><span class="line"><span class="selector-class">.b-menu</span></span><br><span class="line">  <span class="selector-tag">width</span> 25<span class="selector-tag">px</span></span><br><span class="line">  <span class="selector-tag">height</span> 25<span class="selector-tag">px</span></span><br><span class="line">  <span class="selector-tag">position</span> <span class="selector-tag">relative</span></span><br><span class="line">  &amp;:before, // before是第一横杆，after是第二个横杆</span><br><span class="line">  &amp;:after // stylus里的&amp;表示承接上文的意思,这里也就等同于.b-menu:after</span><br><span class="line">    content ' '</span><br><span class="line">    position absolute // 使用绝对定位到目标位置</span><br><span class="line">    <span class="selector-tag">background-color</span> <span class="selector-id">#fff</span></span><br><span class="line">    <span class="selector-tag">display</span> <span class="selector-tag">block</span></span><br><span class="line">    <span class="selector-tag">width</span> 100%</span><br><span class="line">    <span class="selector-tag">height</span> 3<span class="selector-tag">px</span></span><br><span class="line">    <span class="selector-tag">left</span> 0</span><br><span class="line">    <span class="selector-tag">top</span> 11<span class="selector-tag">px</span></span><br><span class="line">    <span class="selector-tag">border-radius</span> 3<span class="selector-tag">px</span></span><br><span class="line">    <span class="selector-tag">transition</span> <span class="selector-tag">all</span> <span class="selector-class">.5s</span></span><br><span class="line">    transform-origin 50% 50% // 设置变换中心点，这个很重要，直接影响到后面的效果</span><br><span class="line">  &amp;<span class="selector-pseudo">:before</span></span><br><span class="line">    transform translateY(-6px) // 第一个横杆向上偏移，这里使用transform而不使用top属性是为了方便后面的使用</span><br><span class="line">  &amp;<span class="selector-pseudo">:after</span></span><br><span class="line">    <span class="selector-tag">box-shadow</span> 0 6<span class="selector-tag">px</span> 0 0 <span class="selector-id">#fff</span></span><br><span class="line">  &amp;:focus:before // 通过focus获取焦点，来触发起伪元素的变化</span><br><span class="line">    <span class="selector-tag">transform</span> <span class="selector-tag">rotateZ</span>(45<span class="selector-tag">deg</span>) <span class="selector-tag">translateY</span>(0)</span><br><span class="line">  &amp;<span class="selector-pseudo">:focus</span><span class="selector-pseudo">:after</span></span><br><span class="line">    <span class="selector-tag">box-shadow</span> 0 0 0 0 <span class="selector-id">#fff</span></span><br><span class="line">    <span class="selector-tag">transform</span> <span class="selector-tag">rotateZ</span>(135<span class="selector-tag">deg</span>) <span class="selector-tag">translateY</span>(0)</span><br></pre></td></tr></table></figure><br><br>### 这个是开关的效果<br>效果是这样的（duang!duang!daung!）<br><img src="http://upload-images.jianshu.io/upload_images/2005796-094b4f13a9f7237d.gif?imageMogr2/auto-orient/strip" alt="switch button"><br><br><iframe height="265" scrolling="no" title="switch button" src="//codepen.io/leenty/embed/jVMmjz/?height=265&theme-id=0&default-tab=css,result&embed-version=2" frameborder="no" allowtransparency="true" allowfullscreen="true" style="width: 100%;">See the Pen <a href="http://codepen.io/leenty/pen/jVMmjz/" target="_blank" rel="noopener">switch button</a> by leenty (<a href="http://codepen.io/leenty" target="_blank" rel="noopener">@leenty</a>) on <a href="http://codepen.io" target="_blank" rel="noopener">CodePen</a>.<br></iframe>

<p><a href="http://codepen.io/leenty/pen/jVMmjz/" target="_blank" rel="noopener">这里是switch button演示地址</a></p>
<p>开关效果又比之前那个复杂，switch的原理其实就是checkbox，<br>因为input是单标签，所以无法使用伪元素，这里就用到了label</p>
<p>核心使用</p>
<ul>
<li>属性：<code>transform</code>, <code>background-size</code>, <code>border-radius</code>, <code>border-width</code>, <code>transition</code>, <code>cubic-bezier</code></li>
<li>标签：<code>label</code></li>
<li>伪元素：<code>:before</code>, <code>:after</code></li>
</ul>
<p>代码如下：<br>html<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">input(id=<span class="string">"switch"</span>,type=<span class="string">"checkbox"</span>).b-switchBtn</span><br><span class="line">label(<span class="keyword">for</span>=<span class="string">"switch"</span>).b-switchLabel</span><br><span class="line"><span class="comment">// label标签利用for属性与相应id的input标签绑定，从而达到点击label就是点击input的效果</span></span><br></pre></td></tr></table></figure></p>
<p>css<br><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">button</span>,</span><br><span class="line"><span class="selector-tag">input</span></span><br><span class="line">  <span class="selector-tag">border</span> <span class="selector-tag">none</span></span><br><span class="line">  <span class="selector-tag">outline</span> <span class="selector-tag">none</span></span><br><span class="line">  <span class="selector-tag">box-shadow</span> <span class="selector-tag">none</span></span><br><span class="line">  <span class="selector-tag">background</span> <span class="selector-tag">none</span></span><br><span class="line">  <span class="selector-tag">color</span> <span class="selector-tag">currentColor</span></span><br><span class="line">  <span class="selector-tag">padding</span> 0</span><br><span class="line">  <span class="selector-tag">cursor</span> <span class="selector-tag">pointer</span></span><br><span class="line">  </span><br><span class="line"><span class="selector-class">.b-switchLabel</span></span><br><span class="line">  <span class="selector-tag">position</span> <span class="selector-tag">relative</span></span><br><span class="line">  <span class="selector-tag">display</span> <span class="selector-tag">inline-block</span></span><br><span class="line">  <span class="selector-tag">width</span> 60<span class="selector-tag">px</span></span><br><span class="line">  <span class="selector-tag">height</span> 25<span class="selector-tag">px</span></span><br><span class="line">  <span class="selector-tag">input</span></span><br><span class="line">    <span class="selector-tag">display</span> <span class="selector-tag">none</span></span><br><span class="line">  &amp;:before, // before 作为白条</span><br><span class="line">  &amp;:after // after 作为水滴状开关</span><br><span class="line">    content ' '</span><br><span class="line">    <span class="selector-tag">display</span> <span class="selector-tag">block</span></span><br><span class="line">    <span class="selector-tag">position</span> <span class="selector-tag">absolute</span></span><br><span class="line">  &amp;<span class="selector-pseudo">:before</span></span><br><span class="line">    <span class="selector-tag">width</span> 100%</span><br><span class="line">    <span class="selector-tag">height</span> 4<span class="selector-tag">px</span></span><br><span class="line">    <span class="selector-tag">background-color</span> <span class="selector-id">#fff</span></span><br><span class="line">    <span class="selector-tag">left</span> 0</span><br><span class="line">    <span class="selector-tag">top</span> 50%</span><br><span class="line">    <span class="selector-tag">border-radius</span> 5<span class="selector-tag">px</span></span><br><span class="line">    <span class="selector-tag">transform</span> <span class="selector-tag">translateY</span>(<span class="selector-tag">-50</span>%)</span><br><span class="line">  &amp;<span class="selector-pseudo">:after</span></span><br><span class="line">    background-image url('http://upload-images.jianshu.io/upload_images/2005796-fcc62a13bd69f679.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240')</span><br><span class="line">    // 因为css不好写出漂亮的水滴效果，所以这里取巧用了图片</span><br><span class="line">    background-size cover // 利用这个属性缩放原来太大的图片</span><br><span class="line">    <span class="selector-tag">height</span> 25<span class="selector-tag">px</span></span><br><span class="line">    <span class="selector-tag">width</span> 25<span class="selector-tag">px</span></span><br><span class="line">    <span class="selector-tag">left</span> 23%</span><br><span class="line">    <span class="selector-tag">top</span> 51%</span><br><span class="line">    <span class="selector-tag">border-radius</span> 25<span class="selector-tag">px</span></span><br><span class="line">    transform-origin center center // 老套路，定下变换中心点</span><br><span class="line">    transform translate(-50%, -50%) // 矫正left和top的偏移</span><br><span class="line">    background-clip border-box // 利用border-box属性值来使背景图片在border上也能显示</span><br><span class="line">    <span class="selector-tag">background-position</span> 50% 50%</span><br><span class="line">    <span class="selector-tag">border-style</span> <span class="selector-tag">solid</span></span><br><span class="line">    border-color transparent // 设置透明border有助于背景的显示</span><br><span class="line">    <span class="selector-tag">border-width</span> 0 3<span class="selector-tag">px</span> 0 0</span><br><span class="line">    transition all .5s cubic-bezier(0.4, -0.95, 0.4, 1.8) // 设置贝塞尔曲线以达到Duang的效果</span><br><span class="line"><span class="selector-class">.b-switchBtn</span></span><br><span class="line">  <span class="selector-tag">display</span> <span class="selector-tag">none</span></span><br><span class="line">  &amp;:checked~.b-switchLabel // 设置开关在被选中时改变状态，配合transition就动了起来</span><br><span class="line">    &amp;<span class="selector-pseudo">:after</span></span><br><span class="line">      <span class="selector-tag">left</span> 78%</span><br><span class="line">      <span class="selector-tag">border-width</span> 0 0 0 3<span class="selector-tag">px</span></span><br></pre></td></tr></table></figure></p>
<p>有疑问的或者有建议的可以在下方留言</p>

      
    </div>
    <div class="article-info article-info-index">
      
      <a href="/2016/11/16/interesting_button_by_css/" class="archive-article-date">
  	<time datetime="2016-11-16T13:19:16.000Z" itemprop="datePublished"><i class="icon-clock"></i>2016-11-16</time>
</a>
      
	<div class="article-tag tagcloud">
		<i class="icon-price-tags"></i>
		<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/css/">css</a></li></ul>
	</div>

      

      <div class="clearfix"></div>
    </div>
  </div>
</article>










  
    <article id="post-css" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-inner">
    
      <input type="hidden" class="isFancy" />
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2016/11/06/css/">使用BEM+emmet的css书写与命名技巧[未完]</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>于日常的项目中，小型项目还好，css即使没怎么规划也不至于特别的乱，但一旦项目里css有一定的基数时，css就会显得混乱起来。<br>于是。。。（以下是案例，可以直接跳至<a href="#main">[正文]有关css命名的部分</a>）</p>
<h3 id="可能就遇到了这种情况"><a href="#可能就遇到了这种情况" class="headerlink" title="可能就遇到了这种情况:"></a>可能就遇到了这种情况:</h3><h4 id="情况1"><a href="#情况1" class="headerlink" title="情况1."></a>情况1.</h4><p>哎呀！这个地方布局有点问题，我改一下，于是看到了一堆css选择器，当你想要修改某个class时又害怕会影响到其他在使用这个class的组件，于是就很尴尬的又写了一个class加在上面。</p>
<h4 id="情况2"><a href="#情况2" class="headerlink" title="情况2."></a>情况2.</h4><p>css命名冲突，你将要命名的class命已经被使用，更惨的是其他意思相近的命名单词也被使用了，这下就词穷了🤕</p>
<h4 id="情况3"><a href="#情况3" class="headerlink" title="情况3."></a>情况3.</h4><p>毫无意义的命名：(写的时候class的意思只有自己和上帝知道，现在只有上帝知道了🙆🏻)<br><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.abc</span> &#123;</span><br><span class="line">    <span class="attribute">width</span>: <span class="number">200px</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>其他前端：一脸懵逼</p>
<h3 id="针对上面的问题，于是就在命名上开始做出改变，然而却😟"><a href="#针对上面的问题，于是就在命名上开始做出改变，然而却😟" class="headerlink" title="针对上面的问题，于是就在命名上开始做出改变，然而却😟"></a>针对上面的问题，于是就在命名上开始做出改变，然而却😟</h3><h4 id="情况4"><a href="#情况4" class="headerlink" title="情况4."></a>情况4.</h4><p>过于语义化的命名（这里举个略微夸张且有些不恰当的栗子🌰）<br><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.navigation-width-full-line</span>&#123;</span><br><span class="line">    <span class="attribute">width</span>: <span class="number">100%</span>;</span><br><span class="line">    <span class="attribute">height</span>: <span class="number">50px</span>;</span><br><span class="line">&#125;</span><br><span class="line">``` </span><br><span class="line">这样是把意义描述清楚了，但是命名却是过长了</span><br><span class="line">#### 情况5. </span><br><span class="line">有语义却不够直接简洁的命名    </span><br><span class="line">```<span class="selector-tag">css</span></span><br><span class="line"><span class="selector-class">.navigation-responsive</span>&#123;</span><br><span class="line">    <span class="attribute">flex</span>: <span class="number">1</span> <span class="number">1</span> <span class="number">10%</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>这样无形中增加了记忆成本</p>
<h3 id="命名规范-BEM"><a href="#命名规范-BEM" class="headerlink" title="命名规范 BEM"></a>命名规范 BEM</h3><p>BEM是我很喜欢的一个命名规范<br>命名规则简单直接又不至于混乱<br>BEM的意思就是块（block）、元素（element）、修饰符（modifier）<br><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">.block &#123;&#125; // 顶级命名，代表了一类元素块或者一个模块</span><br><span class="line">.block__element &#123;&#125; // 次级命名(使用两个英文下划线连接，后跟随次级名称，表示次级元素或属性)</span><br><span class="line">.block--modifier &#123;&#125; // 状态命名(使用两个英文中划线连接，后跟随修饰符或状态名)</span><br></pre></td></tr></table></figure></p>
<p>这样的写法可以的好处是可以避免css的嵌套，可以加快css渲染时的速度<br><strong> 栗子🌰 </strong><br><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- 旧版命名 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"person"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"head"</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"body"</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"foot"</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"pug"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"head"</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"body"</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"foot"</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">style</span>&gt;</span></span><br><span class="line">    // css选择时需要两个class</span><br><span class="line"><span class="css">    <span class="selector-class">.person</span> <span class="selector-class">.head</span> &#123;</span></span><br><span class="line">        width: 100px;</span><br><span class="line">    &#125;</span><br><span class="line"><span class="xml"><span class="tag">&lt;/<span class="name">styles</span>&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="xml"><span class="comment">&lt;!-- BEM命名 --&gt;</span></span></span><br><span class="line"><span class="xml"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"person"</span>&gt;</span></span></span><br><span class="line"><span class="xml">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"person__head"</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line"><span class="xml">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"person__body"</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line"><span class="xml">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"person__foot"</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line"><span class="xml"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line"><span class="xml"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"pug"</span>&gt;</span></span></span><br><span class="line"><span class="xml">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"pug__head"</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line"><span class="xml">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"pug__body"</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line"><span class="xml">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"pug__foot"</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line"><span class="xml"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line"><span class="xml"><span class="tag">&lt;<span class="name">style</span>&gt;</span></span></span><br><span class="line">    // css选择时只要一个class</span><br><span class="line"><span class="css">    <span class="selector-class">.person__head</span> &#123;</span></span><br><span class="line">        width: 100px;</span><br><span class="line">    &#125;</span><br><span class="line"><span class="xml"><span class="tag">&lt;/<span class="name">styles</span>&gt;</span></span></span><br></pre></td></tr></table></figure></p>
<h3 id="BEM-emmet"><a href="#BEM-emmet" class="headerlink" title="BEM+emmet"></a>BEM+emmet</h3><p>相信很多同学有用过emmet,其前身就是大名鼎鼎的Zen coding<br>想了解的同学可以google一下emmet<br>而emmet对于BEM命名规范其实是有一套快速生成标签的规则的<br>发个栗子🌰<br>在emmet下这段代码<br><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">form.search-form&gt;input.-username+input.-password[type=password]+button.-submit--active|bem</span><br></pre></td></tr></table></figure></p>
<p>按下<code>Tab</code>后会生成<br><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">form</span> <span class="attr">class</span>=<span class="string">"search-form"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"text"</span> <span class="attr">class</span>=<span class="string">"search-form__username"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"password"</span> <span class="attr">class</span>=<span class="string">"search-form__password"</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">button</span> <span class="attr">id</span>=<span class="string">"J_Submit"</span> <span class="attr">class</span>=<span class="string">"search-form__submit--active"</span>&gt;</span><span class="tag">&lt;/<span class="name">button</span>&gt;</span> <span class="tag">&lt;<span class="name">form</span>&gt;</span></span><br></pre></td></tr></table></figure></p>
<p>如果仔细看第一段代码与第二段之间的区别就可以看出其中的奥义：</p>
<ul>
<li>首个元素的class选择器会被作为BEM规则的头，后面的每一个以<code>.-</code>开头子元素编译后的class属性都将以这个头为开头</li>
<li>子元素可以以<code>.-</code>开头来代替父元素的class名，省去了重复书写的麻烦(即：<code>.-username</code>被编译成了<code>.search-form__username</code>)</li>
<li>子元素可以跟上<code>--</code>加修饰符来编译(即：<code>.-submit--active</code>被编译成了<code>.search-form__submit--active</code>)</li>
</ul>
<p>这是一种快速生成标签的形式，方便的没话说<br>而有一部分同学已经不再直接写html标签了，而是使用了模板引擎了<br>我用的是pug（也就是之前的jade，现在已经更名为pug了）<br>模板引擎的好处是使整个结构看起来更加清晰有条理，也加快了编写页面的速度，<br>在使用模板引擎后就不在需要emmet了<br>but！<br>虽然不需要了，但是emmet的那种化繁为简的精神是可以继续存在滴，我特别喜欢这样的语法，<br>于是就开始了尝试在css命名上做研究</p>
<p><span id="main"> </span></p>
<h3 id="以下是我vue2-0Demo项目内有关css命名的部分"><a href="#以下是我vue2-0Demo项目内有关css命名的部分" class="headerlink" title="以下是我vue2.0Demo项目内有关css命名的部分"></a>以下是我vue2.0Demo项目内有关css命名的部分</h3><p>一开始看可能会有点懵逼，但是当看完以下6个小点再回头看之前的案例就会明白了<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * css命名使用 BEM+emmet 风格作为命名规范</span></span><br><span class="line"><span class="comment"> * </span></span><br><span class="line"><span class="comment"> * 约定[分类名称][属性|组件名称]与[属性名]使用小写</span></span><br><span class="line"><span class="comment"> * 约定[描述]与[状态]使用首字母大写</span></span><br><span class="line"><span class="comment"> * [eg]:</span></span><br><span class="line"><span class="comment"> *  .[分类名称]-[属性|组件名称][描述]--[属性值|状态]</span></span><br><span class="line"><span class="comment"> *    =&gt; .l-flexV--c</span></span><br><span class="line"><span class="comment"> *    =&gt; .b-base--Active</span></span><br><span class="line"><span class="comment"> * </span></span><br><span class="line"><span class="comment"> *  1.约定 [分类名称] 缩写:</span></span><br><span class="line"><span class="comment"> *    • .layout =&gt; .l- (布局部分)</span></span><br><span class="line"><span class="comment"> *    • .utils =&gt; .u- (工具部分)</span></span><br><span class="line"><span class="comment"> *    • .button =&gt; .b- (按钮部分)</span></span><br><span class="line"><span class="comment"> *    </span></span><br><span class="line"><span class="comment"> *  2.约定通用 [属性] 缩写:(以emmet联想风格为缩写)</span></span><br><span class="line"><span class="comment"> *    • width =&gt; w</span></span><br><span class="line"><span class="comment"> *    • height =&gt; h</span></span><br><span class="line"><span class="comment"> *    • color =&gt; c</span></span><br><span class="line"><span class="comment"> *    • background =&gt; bg</span></span><br><span class="line"><span class="comment"> *    • margin =&gt; m</span></span><br><span class="line"><span class="comment"> *    • padding =&gt; p</span></span><br><span class="line"><span class="comment"> *    • border =&gt; bd</span></span><br><span class="line"><span class="comment"> *    </span></span><br><span class="line"><span class="comment"> *  3.约定通用 [组件名称]:(这里不使用缩写，</span></span><br><span class="line"><span class="comment"> *    因为组件名可以自定义，缩写易混淆，会增加记忆成本)</span></span><br><span class="line"><span class="comment"> *    • flex =&gt; flex (这里所指的是弹性盒子)</span></span><br><span class="line"><span class="comment"> *    </span></span><br><span class="line"><span class="comment"> *  4.约定通用 [描述] 缩写:(以大写)</span></span><br><span class="line"><span class="comment"> *    • horizontal =&gt; H</span></span><br><span class="line"><span class="comment"> *    • vertical =&gt; V</span></span><br><span class="line"><span class="comment"> *    • normal =&gt; N</span></span><br><span class="line"><span class="comment"> *    </span></span><br><span class="line"><span class="comment"> *  5.约定通用 [属性值] 缩写:(以属性前缀 '--' + emmet联想风格为缩写)</span></span><br><span class="line"><span class="comment"> *    • center =&gt; --c</span></span><br><span class="line"><span class="comment"> *    • middle =&gt; --m</span></span><br><span class="line"><span class="comment"> *    • space-around =&gt; --sa</span></span><br><span class="line"><span class="comment"> *    </span></span><br><span class="line"><span class="comment"> *  6.约定通用 [状态] 缩写:(以属性前缀 '--' + 状态首字母大写，</span></span><br><span class="line"><span class="comment"> *    这里不使用缩写，因为状态名可以自定义，缩写易混淆，会增加记忆成本)</span></span><br><span class="line"><span class="comment"> *    • active =&gt; --Active</span></span><br><span class="line"><span class="comment"> */</span></span><br></pre></td></tr></table></figure></p>
<p>因为是一边写vue2.0-demo项目一边写文字，所以以上是暂定的部分，后续有更新会及时在这里更新</p>

      
    </div>
    <div class="article-info article-info-index">
      
      <a href="/2016/11/06/css/" class="archive-article-date">
  	<time datetime="2016-11-06T15:57:50.000Z" itemprop="datePublished"><i class="icon-clock"></i>2016-11-06</time>
</a>
      
	<div class="article-tag tagcloud">
		<i class="icon-price-tags"></i>
		<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/css/">css</a></li></ul>
	</div>

      

      <div class="clearfix"></div>
    </div>
  </div>
</article>










  
    <article id="post-vue2-1" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-inner">
    
      <input type="hidden" class="isFancy" />
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2016/10/21/vue2-1/">vue2.0一起在懵逼的海洋里越陷越深（一）</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>本文章系列：<a href="http://leenty.com/tags/vuejs/" target="_blank" rel="noopener">vue2.0一起在懵逼的海洋里越陷越深 (http://leenty.com/tags/vuejs/)</a></p>
<h3 id="就在今年的10月份，Vue2-0发布啦，来懵逼的海洋里一起下沉吧！"><a href="#就在今年的10月份，Vue2-0发布啦，来懵逼的海洋里一起下沉吧！" class="headerlink" title="就在今年的10月份，Vue2.0发布啦，来懵逼的海洋里一起下沉吧！"></a>就在今年的10月份，Vue2.0发布啦，来懵逼的海洋里一起下沉吧！</h3><p>前段阵子都没有发随笔，一方面要准备一场考试，另一方面是在研究vue2.0，又一方面一时也不知道写点什么好。<br><strong><em>（而其实最大的方面是自己找到了偷懒不写随笔的理由了。。。）</em></strong></p>
<hr>
<p><img src="http://leenty.com/img/vue/vue2.0.png" alt="vue2.0"></p>
<p><strong> @周星星和江南另外三大才子有佳句流传：</strong><br>山下一群鹅，嘘声赶落河.<br>下河捉鹅医肚饿，吃完回家玩…<br>呃…玩vue2.0 咳咳咳咳</p>
<p><strong> 先看看vue2.0多了哪些好玩的 </strong></p>
<ul>
<li>virtual-DOM（据说不是普通的Virtual-DOM）</li>
<li>Templates || JSX || Hyperscript(现在，你可以选择你喜欢的编写模式进行开发了)</li>
<li>流式服务端渲染（这个听起来很厉害，后面一起研究）</li>
<li>其他（各种性能优化，更多想象发挥空间，更多可能）</li>
</ul>
<p><strong> 伴随着vue2.0的更新，vue生态链的其他组件也跟着进行了更新 </strong></p>
<ul>
<li>vue-router</li>
<li>vue-resource</li>
<li>vue-cli</li>
</ul>
<h3 id="好，进入正题"><a href="#好，进入正题" class="headerlink" title="好，进入正题"></a>好，进入正题</h3><p>先贴个地址，<a href="http://vue2.leenty.com" target="_blank" rel="noopener">我的vue2.0的demo</a><br>这个demo使用vue-cli快速生成还发环境<br>加入vue-router做前端路由<br>加入vue-resource做ajax<br>加入vuex做状态管理<br>demo里目前使用hash模式<br>具体的会在接下来一一介绍</p>
<p><strong> 具体细节 </strong></p>
<p>好的，现在打开你的终端，开始开车啦！🚌</p>
<ul>
<li><p>安装vue-cli</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install -g vue-cli</span><br></pre></td></tr></table></figure>
</li>
<li><p>创建vue项目<br>语法：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vue init &lt;template-name&gt; &lt;project-name&gt;</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>这里我选择使用webpack来创建（可以参考<a href="http://leenty.com/2016/06/02/git入门级-在github创建项目/" target="_blank" rel="noopener">git入门级-在github创建项目</a>）<br><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vue init webpack app</span><br></pre></td></tr></table></figure></p>
<p>之后vue-cli就会询问Project name，你可以输入你的工程名，或者直接回车就会默认使用之前的名称<br>之后还会有一系列询问，你可以一路回车下来，这样就创建好了一个<br>大概会是这样子<br><img src="http://leenty.com/img/vue/vue-cli.png" alt="vue-cli"></p>
<ul>
<li>安装依赖<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm i</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>当完成这一步步骤后就可以使用命令启动vue应用了<br><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm run dev</span><br></pre></td></tr></table></figure></p>
<ul>
<li>接下来就安装其他需要的组件，vue-router,vue-resource,vuex<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install vue-router vue-resource vuex --save</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>到这一步，vue项目的骨架已经好了。</p>

      
    </div>
    <div class="article-info article-info-index">
      
      <a href="/2016/10/21/vue2-1/" class="archive-article-date">
  	<time datetime="2016-10-20T17:08:25.000Z" itemprop="datePublished"><i class="icon-clock"></i>2016-10-21</time>
</a>
      
	<div class="article-tag tagcloud">
		<i class="icon-price-tags"></i>
		<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/vuejs/">vuejs</a></li></ul>
	</div>

      

      <div class="clearfix"></div>
    </div>
  </div>
</article>










  
    <article id="post-vim！告别鼠标和触摸板，让你的双手专心的留在键盘上" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-inner">
    
      <input type="hidden" class="isFancy" />
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2016/10/15/vim！告别鼠标和触摸板，让你的双手专心的留在键盘上/">vim！告别鼠标和触摸板，让你的双手专心的留在键盘上[未完]</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="vim从懵懂入坑到生无可恋"><a href="#vim从懵懂入坑到生无可恋" class="headerlink" title="vim从懵懂入坑到生无可恋"></a>vim从懵懂入坑到生无可恋</h3><p><img src="/img/face/mengbiboyi.png" alt="mengbiboyi"></p>
<p>曾经，作为一名前端，也许不用太多在意去刻意的玩bash/shell什么的，毕竟之前的前端不会涉及这方面的需求。</p>
<p>随着node的流行，随着git的流行，各种模块管理器、任务管理器、打包工具的盛行，前端渐渐的也开始接触命令行一类的东西。<br>在使用git处理文件冲突的时候，如果不是用GUI的话，那么就需要使用vim打开冲突的文件进行解决了。</p>
<hr>
<p>vim有3种模式，但常见的也只有两种，即Insert模式和Normal模式<br>其中</p>
<ul>
<li>Insert模式是我们正常的可以输入文本的状态</li>
<li>Normal模式是输入命令的状态<h4 id="模式切换"><a href="#模式切换" class="headerlink" title="模式切换"></a>模式切换</h4><strong>进入Insert模式：</strong></li>
<li>按下<code>I</code>键,即：在当前字符前插入文本</li>
<li>按下<code>shift</code>+<code>I</code>,即：在当前行前插入文本</li>
<li>按下<code>A</code>键,即：在当前字符后追加文本</li>
<li>按下<code>shift</code>+<code>A</code>,即：在当前行后追加文本<br><strong>进入Normal模式(退出Insert模式)：</strong></li>
<li>按下<code>esc</code>键<h4 id="快捷键"><a href="#快捷键" class="headerlink" title="快捷键"></a>快捷键</h4>vim的快捷键基本是在Normal模式下才起作用(废话！Insert模式输快捷键就是输入文本)</li>
</ul>
<p><strong>光标操作</strong></p>
<table>
<thead>
<tr>
<th style="text-align:center">键位</th>
<th>效果</th>
<th><code>shift</code>+当前键位时的效果</th>
<th>数字键+当前键位时的效果</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center"><code>H</code></td>
<td>光标左移</td>
<td>光标移到到当前屏幕第一行</td>
<td>光标移到到当前屏幕第n行</td>
</tr>
<tr>
<td style="text-align:center"><code>J</code></td>
<td>光标下移</td>
<td>合并当前行及下一行</td>
<td></td>
</tr>
<tr>
<td style="text-align:center"><code>K</code></td>
<td>光标上移</td>
<td></td>
<td></td>
</tr>
<tr>
<td style="text-align:center"><code>L</code></td>
<td>光标右移</td>
<td>光标移动到当前屏幕最后一行</td>
<td></td>
</tr>
<tr>
<td style="text-align:center"><code>w</code></td>
<td>光标向后移动到单词头部</td>
<td>光标移动到下一句文本头部</td>
<td></td>
</tr>
<tr>
<td style="text-align:center"><code>B</code></td>
<td>光标向前移动到单词头部</td>
<td>光标移动到上一句文本头部</td>
<td></td>
</tr>
<tr>
<td style="text-align:center"><code>E</code></td>
<td>光标向后移动到单词尾部</td>
<td>光标移动到当前句或者下一句文本尾部</td>
<td></td>
</tr>
<tr>
<td style="text-align:center"><code>^</code></td>
<td>移动光标到行首</td>
<td></td>
<td></td>
</tr>
<tr>
<td style="text-align:center"><code>$</code></td>
<td>移动光标到行尾</td>
<td></td>
<td></td>
</tr>
<tr>
<td style="text-align:center"><code>ctrl</code>+<code>F</code></td>
<td>下一页</td>
<td></td>
<td></td>
</tr>
<tr>
<td style="text-align:center"><code>ctrl</code>+<code>B</code></td>
<td>上一页</td>
<td></td>
<td></td>
</tr>
<tr>
<td style="text-align:center"><code>G</code></td>
<td></td>
<td>移动到末行</td>
<td>移动到第n行</td>
</tr>
<tr>
<td style="text-align:center"><code>G</code>+<code>G</code></td>
<td>移动到首行</td>
<td></td>
<td></td>
</tr>
<tr>
<td style="text-align:center"><code>)</code></td>
<td>移动到下一句</td>
<td></td>
<td></td>
</tr>
<tr>
<td style="text-align:center"><code>(</code></td>
<td>移动到上一句</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>

      
    </div>
    <div class="article-info article-info-index">
      
      <a href="/2016/10/15/vim！告别鼠标和触摸板，让你的双手专心的留在键盘上/" class="archive-article-date">
  	<time datetime="2016-10-15T08:02:50.000Z" itemprop="datePublished"><i class="icon-clock"></i>2016-10-15</time>
</a>
      
	<div class="article-tag tagcloud">
		<i class="icon-price-tags"></i>
		<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/vim/">vim</a></li></ul>
	</div>

      

      <div class="clearfix"></div>
    </div>
  </div>
</article>










  
    <article id="post-利用host域名解析解决github访问慢问题" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-inner">
    
      <input type="hidden" class="isFancy" />
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2016/10/14/利用host域名解析解决github访问慢问题/">利用host域名解析解决github访问慢问题</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="起因"><a href="#起因" class="headerlink" title="起因"></a>起因</h3><p>最近家里访问github速度越来越慢，今天已经是异常的慢了，于是开始寻找解决的办法<br>遇到打不开的网站，本能的搬起‘梯子‘去翻墙，问题就这么解决了。。。<br><strong><em>不对啊！我去！</em></strong><br><strong><em>github什么时候需要翻墙访问啦？</em></strong></p>
<h3 id="so"><a href="#so" class="headerlink" title="so"></a>so</h3><p>我开始寻找不翻墙的方法。<br>先看这张图<br><img src="/img/github-network.png" alt="github-network"><br>发现其实github.com的响应速度并不慢，而真正拖慢速度的是assets-cdn.github.com（其中pending的部分）<br>这基本是由dns污染所导致，所以只要通过host映射到一个畅通的IP上就会变的好起来。<br>进入一个<a href="http://tool.chinaz.com/dns" target="_blank" rel="noopener">dns域名检测</a>的网站，在其中查询assets-cdn.github.com<br>会搜出一个dns列表，选择其中TTL值最小的一个IP，复制出来<br>命令行工具打开你的hosts文件（这里以macOS为例,如果你使用windows的git命令行工具，操作就是差不多的）<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo vim /etc/hosts</span><br></pre></td></tr></table></figure></p>
<p>在hosts文件最下方添加刚刚复制出来的IP<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">151.101.xxx.xxx assets-cdn.github.com</span><br></pre></td></tr></table></figure></p>
<p><strong>具体vim操作步骤：</strong></p>
<ol>
<li>按下<code>shift + g</code>跳至页尾</li>
<li>按下<code>o</code>创建新的一行</li>
<li>按下<code>ctrl/command + v</code> 粘贴刚刚复制的IP</li>
<li>而后打个空格</li>
<li>接着输入<code>assets-cdn.github.com</code></li>
<li>按下<code>esc</code>退出编辑模式</li>
<li>输入<code>:wq</code>保存退出<br>如此就大功告成了。<br>如果还不会用vim，也可以用其他编辑器打开做修改。<br>保存之后，就可以尝试再次访问github了，多刷几遍就能进去。<br>如果还是进不去可以输入命令<code>sudo dscacheutil -flushcache</code>更新dns缓存，这样就可以进入了。</li>
</ol>

      
    </div>
    <div class="article-info article-info-index">
      
      <a href="/2016/10/14/利用host域名解析解决github访问慢问题/" class="archive-article-date">
  	<time datetime="2016-10-14T14:57:09.000Z" itemprop="datePublished"><i class="icon-clock"></i>2016-10-14</time>
</a>
      
	<div class="article-tag tagcloud">
		<i class="icon-price-tags"></i>
		<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/other/">other</a></li></ul>
	</div>

      

      <div class="clearfix"></div>
    </div>
  </div>
</article>










  
  
    <nav id="page-nav">
      <a class="extend prev" rel="prev" href="/">&laquo; Prev</a><a class="page-number" href="/">1</a><span class="page-number current">2</span><a class="page-number" href="/page/3/">3</a><a class="page-number" href="/page/4/">4</a><a class="extend next" rel="next" href="/page/3/">Next &raquo;</a>
    </nav>
  


      </div>
      <footer id="footer">
  <div class="outer">
    <div id="footer-info">
    	<div class="footer-left">
    		&copy; 2019 leenty
    	</div>
      	<div class="footer-right">
      		<a href="http://hexo.io/" target="_blank">Hexo</a>  Theme <a href="https://github.com/litten/hexo-theme-yilia" target="_blank">Yilia</a> by Litten
      	</div>
    </div>
  </div>
</footer>
    </div>
    <script>
	var yiliaConfig = {
		fancybox: true,
		mathjax: false,
		animate: true,
		isHome: true,
		isPost: false,
		isArchive: false,
		isTag: false,
		isCategory: false,
		open_in_new: false,
		root: "/",
		innerArchive: true
	}
</script>

<script src="/./main.js"></script>


    
<div class="tools-col">
  <ul class="btn-wrap">
    
      <li class="chose" data-hook="tools-section-all"><span class="text">全部</span><i class="icon-book"></i></li>
    
    
      <li data-hook="tools-section-tag"><span class="text">标签</span><i class="icon-price-tags"></i></li>
    
    
      <li data-hook="tools-section-friends"><span class="text">友链</span><i class="icon-link"></i></li>
    
    
      <li data-hook="tools-section-me"><span class="text">我</span><i class="icon-smile"></i></li>
    
  </ul>
  <div class="tools-wrap">
    
    	<section class="tools-section tools-section-all chose">
    	</section>
    

    
    	<section class="tools-section tools-section-tag">
    			<div class="widget tagcloud" id="js-tagcloud">
    				<a href="/tags/ES6/" style="font-size: 10px;">ES6</a> <a href="/tags/css/" style="font-size: 15px;">css</a> <a href="/tags/git/" style="font-size: 10px;">git</a> <a href="/tags/github/" style="font-size: 10px;">github</a> <a href="/tags/gulp/" style="font-size: 10px;">gulp</a> <a href="/tags/hexo/" style="font-size: 12.5px;">hexo</a> <a href="/tags/js/" style="font-size: 12.5px;">js</a> <a href="/tags/other/" style="font-size: 10px;">other</a> <a href="/tags/sublime/" style="font-size: 10px;">sublime</a> <a href="/tags/vim/" style="font-size: 10px;">vim</a> <a href="/tags/vue-router/" style="font-size: 17.5px;">vue-router</a> <a href="/tags/vuejs/" style="font-size: 20px;">vuejs</a> <a href="/tags/vuex/" style="font-size: 12.5px;">vuex</a>
    			</div>
    	</section>
    

    
    	<section class="tools-section tools-section-friends">
  		
  			<div class="friends-wrap" id="js-friends">
  			
  	          <a target="_blank" class="main-nav-link switch-friends-link" href="http://vue2.leenty.com">vue2.0演示地址</a>
  	        
  	          <a target="_blank" class="main-nav-link switch-friends-link" href="http://www.leenty.com/">leenty的博客</a>
  	        
  	          <a target="_blank" class="main-nav-link switch-friends-link" href="https://whqet.github.io/">whqet的博客</a>
  	        
  	          <a target="_blank" class="main-nav-link switch-friends-link" href="https://shenyubin.github.io/">沈雨彬的博客</a>
  	        
  	          <a target="_blank" class="main-nav-link switch-friends-link" href="http://www.deboy.cn">Deboy的博客</a>
  	        
  	        </div>
  		
    	</section>
    

    
    	<section class="tools-section tools-section-me">
  	  	
  	  		<div class="aboutme-wrap" id="js-aboutme">不会捣(xia)鼓(gao)的前端不是好全栈</div>
  	  	
    	</section>
    
  </div>
  
</div>
    <!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                      <div class="pswp__preloader__cut">
                        <div class="pswp__preloader__donut"></div>
                      </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div> 
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>
  </div>
</body>
</html>